package com.cyl.game.demos.web.controller;

import org.springframework.web.bind.annotation.*;
import java.util.List;

import javax.annotation.Resource;

import com.cyl.game.demos.web.entity.Friendship;
import com.cyl.game.demos.web.service.FriendshipService;

@RestController
@RequestMapping("/friendships")
public class FriendshipController {

    @Resource
    private FriendshipService friendshipService;
   // 添加双向好友关系
   @PostMapping("/add")
   public String addFriendship(@RequestBody Friendship friendship) {
       friendshipService.addFriendship(friendship);
       return "双向好友关系添加成功";
   }

   // 根据用户 ID 查询该用户的所有好友关系
   @GetMapping("/{user_id}")
   public List<Friendship> getFriendshipsByUserId(@PathVariable("user_id") Integer user_id) {
       return friendshipService.getFriendshipsByUserId(user_id);
   }

   // 判断两个用户是否为双向好友关系
   @GetMapping("/check/{user_id_1}/{user_id_2}")
   public boolean isFriendship(@PathVariable("user_id_1") Integer user_id_1, @PathVariable("user_id_2") Integer user_id_2) {
       return friendshipService.isFriendship(user_id_1, user_id_2);
   }

   // 删除双向好友关系（解除好友关系操作）
   @DeleteMapping("/{user_id_1}/{user_id_2}")
   public String deleteFriendship(@PathVariable("user_id_1") Integer user_id_1, @PathVariable("user_id_2") Integer user_id_2) {
       friendshipService.deleteFriendship(user_id_1, user_id_2);
       return "双向好友关系删除成功";
   }
}